<?php
session_start();
if ($_SESSION['connecte']==1)
{
	require_once ("../jpGraph/jpgraph.php");
	require_once ("../jpGraph/jpgraph_pie.php");
	require_once ("../fct_config.inc.php");
	require_once ("../outils.php");

	require_once ("../baniere.php");

	$bordure="0";

	//connection à la base
	$link = mysql_connect(HOST,USER,PASS);
	mysql_select_db(BASE, $link);


	$debPeriode=dateInverseEntree("01/01".date("/Y"));


	//choix du mode de statistiques
	if($_GET['detail']=="mois"){
		$deb=dateInverseEntree("01".date("/m/Y"));
		$moisSvt=date("m")+1;
		if($moisSvt<10){
			$moisSvt="0".$moisSvt;
		}
		//		$fin=	dateInverseEntree("01/".$moisSvt.date("/Y"));

		$mois = mktime( 0, 0, 0, date("m"), 1, date("Y"));

		$fin=dateInverseEntree(date("t",$mois).date("/m").date("/Y"));

		if($_GET['debut']=="")
		$_GET['debut']=date("d/m/Y");
		if($_GET['fin']=="")
		$_GET['fin']=date("d/m/Y");
		$nomMois=conversionDate(date("m"));

		$periode=$nomMois." ".date("Y");

		$titre = $distribution."Statistiques du mois en cours : ".$nomMois." ".date("Y");
		print "<center><h1>".$titre."</h1></center>";
		//print "<center><a href=\"statistiques/detailPdf.php?detail=mois&nbFamille=".$nbFamille[nbFamille]."&nbFamilleBene=".$nbFamilleBene[nbFamilleBene]."&nbSortie=".$nbSortie[nbSortie]."&nbBene=".$nbBene[nbBene]."&mois=".date("m")."&annee=".date("Y")."&hauteur=".$hauteurGraph."&largeur=".$largeurGraph."\">Générer le rapport en PDF</a></center><br/>";

	}
	else if($_GET['detail']=="annee"){
		$deb=dateInverseEntree("01/01".date("/Y"));
		$fin=dateInverseEntree("31/12".date("/Y"));
		$periode="Année ".date("Y");
		$titre = $distribution."Statistiques de l'année en cours : ".date("Y");
		print "<center><h1>".$titre."</h1></center>";
		//print "<center><a href=\"statistiques/detailPdf.php?detail=annee&nbFamille=".$nbFamille[nbFamille]."&nbFamilleBene=".$nbFamilleBene[nbFamilleBene]."&nbSortie=".$nbSortie[nbSortie]."&nbBene=".$nbBene[nbBene]."&debut=".$deb."&fin=".$fin."&hauteur=".$hauteurGraph."&largeur=".$largeurGraph."\">Générer le rapport en PDF</a></center><br/>";
	}
	else if($_GET['detail']=="tout"){
		$titre = $distribution."Statistiques de la globalité de la base";
		print "<center><h1>".$titre."</h1></center>";
		$periode="Globalité de la base";
		$deb=dateInverseEntree("01/01/2000");
		$fin=dateInverseEntree("31/12/2100");
	}
	else{
		if($_GET['mois']<13){
			$_GET['detail']="moisPerso";
			$mois=$_GET['mois'];
			$annee=$_GET['annee'];
			$debPeriode=dateInverseEntree("01/01/".$annee);
				
			$deb = "01/".$mois."/".$annee;
			$moisf = mktime( 0, 0, 0, $mois, 1, $annee);
			$fin=date("t",$moisf)."/".$mois."/".$annee;
				
			$nomMois=conversionDate($mois);
			$periode=$nomMois." ".$annee;
			$titre = $distribution."Statistiques de ".$nomMois." ".date("Y");
			print "<center><h1>".$titre."</h1></center>";
		}
		else {
			$_GET['detail']="anneePerso";
			$annee=$_GET['annee'];
			$deb = "01/01/".$annee;
			$fin = "31/12/".$annee;
			$periode="Année ".$annee;
			$titre = $distribution."Statistiques de l'année ".date("Y");
			print "<center><h1>".$titre."</h1></center>";
		}
		$deb=dateInverseEntree($deb);
		$fin=dateInverseEntree($fin);
	}

	$periode2="Du ".dateInverseSortie($deb)." au ".dateInverseSortie($fin);

	//nb de nouvelles Familles
	$nbNewFamille=mysql_fetch_array(mysql_query("select count(*) as nbFamille from FAMILLE
		where dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."'"));		
	//nb de Familles total
	$nbFamille=mysql_fetch_array(mysql_query("select count(*) as nbFamille from FAMILLE
		WHERE ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));

		//nb de nouvelles Familles Bene
		$nbNewFamilleBene=mysql_fetch_array(mysql_query("select count(*) as nbFamilleBene from FAMILLE
			where dateInscription>='".$deb."' 
			AND dateInscription<='".$fin."' 
		AND beneDistribution=1"));
		//nb de Familles Bene
		$nbFamilleBene=mysql_fetch_array(mysql_query("select count(*) as nbFamilleBene from FAMILLE
		where beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));

		//nb de nouveaux Bene
		$nbNewBene=mysql_fetch_array(mysql_query("select COALESCE(sum(nbBeneficiaires),0) as nbBene from FAMILLE
		where beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."'"));
		//nb de Bene Total
		$nbBene=mysql_fetch_array(mysql_query("select COALESCE(sum(nbBeneficiaires),0) as nbBene from FAMILLE
		where beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));

		//nb de nouveaux Isoles
		$nbNewIsoles=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbIsoles
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND (
			s.libelleSituation = 'I0'
			OR s.libelleSituation = 'C0')
			AND dateInscription>='".$deb."' 
			AND dateInscription<='".$fin."'"));
		//nb Isoles total
		$nbIsoles=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbIsoles
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND (
			s.libelleSituation = 'I0'
			OR s.libelleSituation = 'C0'
			)
			AND ((dateSortie>='".$deb."' 
			AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
			));

			//nb nouveau hommes Isoles
			$nbNewHommeIsoles=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbHommesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND c.libelleCivilite = 'Mr'
		AND f.situation = s.noSituation
		AND s.libelleSituation = 'I0'
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."'"));
			//nb hommes Isoles total
			$nbHommeIsoles=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbHommesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND c.libelleCivilite = 'Mr'
		AND f.situation = s.noSituation
		AND s.libelleSituation = 'I0'
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));

		//nb new femmes Isoles
		$nbNewFemmeIsoles=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbFemmesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND (
		c.libelleCivilite = 'Mme'
		OR c.libelleCivilite = 'Mlle')	
		AND f.situation = s.noSituation
		AND s.libelleSituation = 'I0'
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."'"));
		//nb Femmes Isoles total
		$nbFemmeIsoles=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbFemmesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND (
		c.libelleCivilite = 'Mme'
		OR c.libelleCivilite = 'Mlle')	
		AND f.situation = s.noSituation
		AND s.libelleSituation = 'I0'		
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));
















		//nb de nouveaux Isoles
		$nbNewIsolesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbIsoles
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND (
			s.libelleSituation = 'I1'
			OR s.libelleSituation = 'I2'
			OR s.libelleSituation = 'I3'
			OR s.libelleSituation = 'I4'
			OR s.libelleSituation = 'I5')
			AND dateInscription>='".$deb."' 
			AND dateInscription<='".$fin."'"));
		//nb Isoles total
		$nbIsolesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbIsoles
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND (
			s.libelleSituation = 'I1'
			OR s.libelleSituation = 'I2'
			OR s.libelleSituation = 'I3'
			OR s.libelleSituation = 'I4'
			OR s.libelleSituation = 'I5')		
			AND ((dateSortie>='".$deb."' 
			AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
			));

			//nb new hommes Isoles
			$nbNewHommeIsolesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbHommesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND c.libelleCivilite = 'Mr'
		AND f.situation = s.noSituation
		AND (
		s.libelleSituation = 'I1'
		OR s.libelleSituation = 'I2'
		OR s.libelleSituation = 'I3'
		OR s.libelleSituation = 'I4'
		OR s.libelleSituation = 'I5')
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."'"));
			//nb hommes Isoles total
			$nbHommeIsolesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbHommesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND c.libelleCivilite = 'Mr'
		AND f.situation = s.noSituation
		AND (
		s.libelleSituation = 'I1'
		OR s.libelleSituation = 'I2'
		OR s.libelleSituation = 'I3'
		OR s.libelleSituation = 'I4'
		OR s.libelleSituation = 'I5'
		)		
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));

		//nb femmes Isoles total
		$nbNewFemmeIsolesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbFemmesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND (
		c.libelleCivilite = 'Mme'
		OR c.libelleCivilite = 'Mlle')	
		AND f.situation = s.noSituation
		AND (
		s.libelleSituation = 'I1'
		OR s.libelleSituation = 'I2'
		OR s.libelleSituation = 'I3'
		OR s.libelleSituation = 'I4'
		OR s.libelleSituation = 'I5')
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."'"));
		//nb Femmes Isoles total
		$nbFemmeIsolesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbFemmesIsoles
		FROM FAMILLE f, SITUATION s, CIVILITE c
		WHERE f.beneDistribution =1
		AND f.civilite = c.noCivilite
		AND (
		c.libelleCivilite = 'Mme'
		OR c.libelleCivilite = 'Mlle')	
		AND f.situation = s.noSituation
		AND (
		s.libelleSituation = 'I1'
		OR s.libelleSituation = 'I2'
		OR s.libelleSituation = 'I3'
		OR s.libelleSituation = 'I4'
		OR s.libelleSituation = 'I5'
		)
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
		));







		//nb Couple sans enfant
		$nbNewCouples=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbCouples
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND s.libelleSituation = 'C0'
			AND dateInscription>='".$deb."' 
			AND dateInscription<='".$fin."'"));
		//nb Couple sans enfant
		$nbCouples=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbCouples
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND s.libelleSituation = 'C0'
			AND ((dateSortie>='".$deb."' 
			AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
			));

			//nb Couple avec enfants
			$nbNewCouplesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbCouples
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND (
			s.libelleSituation = 'C1'
			OR s.libelleSituation = 'C2'
			OR s.libelleSituation = 'C3'
			OR s.libelleSituation = 'C4'
			OR s.libelleSituation = 'C5'
			OR s.libelleSituation = 'C6'
			OR s.libelleSituation = 'C7'
			OR s.libelleSituation = 'C8'
			OR s.libelleSituation = 'C9'
			)
			AND dateInscription>='".$deb."' 
			AND dateInscription<='".$fin."'"));

			//nb Couple avec enfants
			$nbCouplesAcEnfants=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbCouples
			FROM FAMILLE f, SITUATION s
			WHERE f.beneDistribution =1
			AND f.situation = s.noSituation
			AND (
			s.libelleSituation = 'C1'
			OR s.libelleSituation = 'C2'
			OR s.libelleSituation = 'C3'
			OR s.libelleSituation = 'C4'
			OR s.libelleSituation = 'C5'
			OR s.libelleSituation = 'C6'
			OR s.libelleSituation = 'C7'
			OR s.libelleSituation = 'C8'
			OR s.libelleSituation = 'C9')
			AND ((dateSortie>='".$deb."' 
			AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')"
			));







			//nb de nouvelles sorties
			$nbNewSortie=mysql_fetch_array(mysql_query("select count(*) as nbSortie from FAMILLE
		where dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."'"));
			//nb de sorties total
			//$nbSortie=mysql_fetch_array(mysql_query("select count(*) as nbSortie from FAMILLE
			//where dateSortie<>'0000-00-00'"));


			/*$nbSortie=mysql_fetch_array(mysql_query("select count(*) as nbSortie from FAMILLE
			 where dateSortie<>'0000-00-00' AND dateSortie<='".$fin."'"));
			 */
				
			$nbSortie=mysql_fetch_array(mysql_query("select count(*) as nbSortie from FAMILLE
		where dateSortie<>'0000-00-00' AND dateSortie>='".$debPeriode."' and dateSortie<='".$fin."'"));


			//nb de nouveaux depannages
			$nbNewDep=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbDep
		FROM DUR d, ETAT e
		WHERE d.etat=e.noEtat
		AND e.libelleEtat = 'Depannage' AND d.dateDUR >='".$deb."'
		AND d.dateDUR <='".$fin."'"));

			//nb de depannages total
			$nbDep=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbDep
		FROM DUR d, ETAT e
		WHERE d.etat=e.noEtat
		AND e.libelleEtat = 'Depannage'
		AND dateDUR<='".$debPeriode."'
		AND dateDUR<='".$fin."'"
		));

		//nb de nouvelles urgences
		$nbNewUrgence=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbUrgence
		FROM DUR d, ETAT e
		WHERE d.etat=e.noEtat
		AND e.libelleEtat = 'Urgence'
		AND d.dateDUR >='".$deb."'
		AND d.dateDUR <='".$fin."'"));

		//nb durgence total
		$nbUrgence=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbUrgence
		FROM DUR d, ETAT e
		WHERE d.etat=e.noEtat
		AND e.libelleEtat = 'Urgence'
		AND dateDUR<='".$debPeriode."'
		AND dateDUR<='".$fin."'"
		));


		//nb de nouveaux refus
		$nbNewRefus=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbRefus
		FROM DUR d, ETAT e
		WHERE d.etat=e.noEtat
		AND e.libelleEtat = 'Refus'
		AND d.dateDUR >='".$deb."'
		AND d.dateDUR <='".$fin."'"));
		//nb de refus total
		$nbRefus=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbRefus
		FROM DUR d, ETAT e
		WHERE d.etat=e.noEtat
		AND e.libelleEtat = 'Refus'
		AND dateDUR<='".$debPeriode."'
		AND dateDUR<='".$fin."'"
		));


		//nb de nouveaux renouvellements
		$nbNewRenouvellement=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbRenouvellement
		FROM FAMILLE f, RENOUVELLEMENT r
		WHERE f.beneDistribution =1
		AND r.famille = f.noFamille
		AND r.dateRenou >='".$deb."'
		AND r.dateRenou <='".$fin."'"));
		//nb de Renouvellement total
		$nbRenouvellement=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbRenouvellement
		FROM FAMILLE f, RENOUVELLEMENT r
		WHERE f.beneDistribution =1
		AND r.famille = f.noFamille
		AND r.dateRenou<='".$debPeriode."'
		AND r.dateRenou<='".$fin."'"
		));



		//nb de nouveaux entretien
		$nbNewEntretiens=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbEntretiens
		FROM FAMILLE f, ENTRETIEN e
		WHERE f.beneDistribution =1
		AND e.famille = f.noFamille
		AND e.dateEntretien >='".$deb."'
		AND e.dateEntretien <='".$fin."'"));

		//nb de entretiens total
		$nbEntretiens=mysql_fetch_array(mysql_query("SELECT COUNT( * ) AS nbEntretiens
		FROM FAMILLE f, ENTRETIEN e
		WHERE f.beneDistribution =1
		AND e.famille = f.noFamille
		AND e.dateEntretien<='".$debPeriode."'
		AND e.dateEntretien<='".$fin."'"
		));

		print "<center><a href=\"statistiques/detailPdf.php?titre=".$titre."
		&nbFamille=".$nbFamille[nbFamille]."
		&nbNewFamille=".$nbNewFamille[nbFamille]."
		&nbFamilleBene=".$nbFamilleBene[nbFamilleBene]."
		&nbNewFamilleBene=".$nbNewFamilleBene[nbFamilleBene]."
		&nbBene=".$nbBene[nbBene]."
		&nbNewBene=".$nbNewBene[nbBene]."
		&nbIsoles=".$nbIsoles[nbIsoles]."
		&nbNewIsoles=".$nbNewIsoles[nbIsoles]."
		&nbHommeIsoles=".$nbHommeIsoles[nbHommesIsoles]."
		&nbNewHommeIsoles=".$nbNewHommeIsoles[nbHommesIsoles]."
		&nbFemmeIsoles=".$nbFemmeIsoles[nbFemmesIsoles]."
		&nbNewFemmeIsoles=".$nbNewFemmeIsoles[nbFemmesIsoles]."
		&nbHommeIsolesAcEnfants=".$nbHommeIsolesAcEnfants[nbHommesIsoles]."
		&nbNewHommeIsolesAcEnfants=".$nbNewHommeIsolesAcEnfants[nbHommesIsoles]."
		&nbFemmeIsolesAcEnfants=".$nbFemmeIsolesAcEnfants[nbFemmesIsoles]."
		&nbNewFemmeIsolesAcEnfants=".$nbNewFemmeIsolesAcEnfants[nbFemmesIsoles]."
		&nbCouples=".$nbCouples[nbCouples]."
		&nbNewCouples=".$nbNewCouples[nbCouples]."
		&nbCouplesAcEnfants=".$nbCouplesAcEnfants[nbCouples]."
		&nbNewCouplesAcEnfants=".$nbNewCouplesAcEnfants[nbCouples]."
		&nbSortie=".$nbSortie[nbSortie]."
		&nbNewSortie=".$nbNewSortie[nbSortie]."
		&nbDep=".$nbDep[nbDep]."
		&nbNewDep=".$nbNewDep[nbDep]."
		&nbUrgence=".$nbUrgence[nbUrgence]."
		&nbNewUrgence=".$nbNewUrgence[nbUrgence]."
		&nbRefus=".$nbRefus[nbRefus]."
		&nbNewRefus=".$nbNewRefus[nbRefus]."
		&nbEntretiens=".$nbEntretiens[nbEntretiens]."
		&nbNewEntretiens=".$nbNewEntretiens[nbEntretiens]."
		&nbRenouvellement=".$nbRenouvellement[nbRenouvellement]."
		&nbNewRenouvellement=".$nbNewRenouvellement[nbRenouvellement]."
		&periode=".$periode."
		&periode2=".$periode2."
		&debut=".$deb."
		&fin=".$fin."
		&hauteur=".$hauteurGraph."
		&largeur=".$largeurGraph."\">Générer le rapport en PDF</a></center><br/>";	

		if($_GET['detail']=="mois" || $_GET['detail']=="moisPerso" ){
			$queryCivilite="select count(*) as nbCivilite, libelleCivilite from CIVILITE c, FAMILLE f
		where c.noCivilite=f.civilite 
		AND beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."' 	
		group by noCivilite order by libelleCivilite";

			$queryAge="select count(*) as nbAge, libelleAge from AGE a, FAMILLE f
		where a.noAge=f.age  
		AND beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."' 
		group by noAge order by libelleAge";
				
			$querySituation="select count(*) as nbSituation, libelleSituation from SITUATION s, FAMILLE f
		where s.noSituation=f.situation  
		AND beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."' 
		group by noSituation order by libelleSituation";

			$queryRessource="select count(*) as nbRessource, libelleRessource from RESSOURCE r, FAMILLE f
		where r.noRessource=f.ressource  
		AND beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."' 
		group by noRessource order by libelleRessource";

			$queryOrganisme="select count(*) as nbOrganisme, libelleOrganisme from ORGANISME o, FAMILLE f
		where o.noOrganisme=f.organisme  
		AND beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."' 
		group by noOrganisme order by libelleOrganisme";

			$queryLogement="select count(*) as nbLogement, libelleLogement from LOGEMENT l, FAMILLE f
		where l.noLogement=f.logement  
		AND beneDistribution=1
		AND dateInscription>='".$deb."' 
		AND dateInscription<='".$fin."' 
		group by noLogement order by libelleLogement";

			$queryEtat="select count(*) as nbEtat, libelleEtat from DUR d, ETAT e
		where d.etat=e.noEtat  
		AND dateDur>='".$deb."' 
		AND dateDur<='".$fin."' 
		group by etat order by libelleEtat";
		}
		else if($_GET['detail']=="annee" || $_GET['detail']=="anneePerso" ){
			$queryCivilite="select count(*) as nbCivilite, libelleCivilite from CIVILITE c, FAMILLE f
		where c.noCivilite=f.civilite 
		AND beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')
		group by noCivilite order by libelleCivilite";

			$queryAge="select count(*) as nbAge, libelleAge from AGE a, FAMILLE f
		where a.noAge=f.age  
		AND beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')
		group by noAge order by libelleAge";
				
			$querySituation="select count(*) as nbSituation, libelleSituation from SITUATION s, FAMILLE f
		where s.noSituation=f.situation  
		AND beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')
		group by noSituation order by libelleSituation";

			$queryRessource="select count(*) as nbRessource, libelleRessource from RESSOURCE r, FAMILLE f
		where r.noRessource=f.ressource  
		AND beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')
		group by noRessource order by libelleRessource";

			$queryOrganisme="select count(*) as nbOrganisme, libelleOrganisme from ORGANISME o, FAMILLE f
		where o.noOrganisme=f.organisme  
		AND beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')
		group by noOrganisme order by libelleOrganisme";

			$queryLogement="select count(*) as nbLogement, libelleLogement from LOGEMENT l, FAMILLE f
		where l.noLogement=f.logement  
		AND beneDistribution=1
		AND ((dateSortie>='".$deb."' 
		AND dateSortie<='".$fin."') OR dateSortie='0000-00-00')
		group by noLogement order by libelleLogement";

			$queryEtat="select count(*) as nbEtat, libelleEtat from DUR d, ETAT e
		where d.etat=e.noEtat  
		AND dateDUR<='".$deb."'
		AND dateDUR<='".$fin."' 
		group by etat order by libelleEtat";

		}
		else if($_GET['detail']=="tout"){

		}

		include("./graph.php");
}
else
{
	print "Vous devez vous connecter avant tout :  <a href=\"../index.php\">Se connecter </a>";
}
print("</body>\n");
print("</html>\n");
?>
